import Vue from 'vue';
import Router from 'vue-router';


Vue.use(Router);

export const page404 = {
  path: '/*',
  name: 'error-404',
  meta: {
    title: '404-页面不存在'
  },
  component: resolve => {
    require(['@/views/error-page/404.vue'], resolve);
  }
};

export const page403 = {
  path: '/403',
  meta: {
    title: '403-权限不足'
  },
  name: 'error-403',
  component: resolve => {
    require(['@/views/error-page/403.vue'], resolve);
  }
};

export const page500 = {
  path: '/500',
  meta: {
    title: '500-服务端错误'
  },
  name: 'error-500',
  component: resolve => {
    require(['@/views/error-page/500.vue'], resolve);
  }
};

// 不作为Main组件的子页面展示的页面单独写，如下
export const loginRouter = {
  path: '/login',
  name: 'login',
  meta: {
    title: 'Login - 登录'
  },
  component: resolve => {
    require(['@/views/login/login.vue'], resolve);
  }
};

export const indexRouter = {
  path: '/index',
  name: 'index',
  meta: {
    title: '主页'
  },
  component: resolve => {
    require(['@/views/index/index.vue'], resolve);
  }
};

export const demoRouter = {
  path: '/demo',
  name: 'demo',
  meta: {
    title: '例子'
  },
  component: resolve => {
    require(['@/views/demo/demo.vue'], resolve);
  },
  children: [
    {
      path: 'webstart',
      title: 'webstart',
      meta: {title: 'webstart 网页启动java例子'},
      name: 'webstart',
      component: resolve => {
        require(['@/views/demo/webstart/webstart.vue'], resolve);
      }
    }
  ]
};

export const adminRouter = {
  path: '/admin',
  name: 'admin',
  meta: {
    title: '后台管理 - admin'
  },
  component: resolve => {
    require(['@/views/admin/admin.vue'], resolve);
  },
  children: [
    {
      path: 'user-manager', title: '用户管理',meta: { title: '用户管理 -user-manager',menuId:1 }, name: 'user-manager', component: resolve => {
        require(['@/views/admin/user-manager/userManager.vue'], resolve);
      }
    },
    {
      path: 'org-manager', title: '机构管理', name: 'org-manager', component: resolve => {
        require(['@/views/admin/org-manager/orgManager.vue'], resolve);
      }
    }
    ,
    {
      path: 'menu-manager', title: '机构管理', name: 'menu-manager', component: resolve => {
        require(['@/views/admin/menu-manager/menuManager.vue'], resolve);
      }
    },
    {
      path: 'role-manager', title: '角色管理', name: 'role-manager', component: resolve => {
        require(['@/views/admin/role-manager/roleManager.vue'], resolve);
      }
    },
    {
      path: 'permission-manager/role-manager', title: '角色管理', name: 'permission-manager/role-manager', component: resolve => {
        require(['@/views/admin/role-manager/roleManager.vue'], resolve);
      }
    },
    {
      path: 'permission-manager/userRole-manager', title: '实例管理', name: 'permission-manager/userRole-manager', component: resolve => {
        require(['@/views/admin/role-manager/userRoleManager.vue'], resolve);
      }
    },
    {
      path: 'dict-manager', title: '字典管理', name: 'dict-manager', component: resolve => {
        require(['@/views/admin/dict-manager/dictManager.vue'], resolve);
      }
    },
    {
      path: 'file-manager', title: '文件管理', name: 'file-manager', component: resolve => {
        require(['@/views/admin/file-manager/fileManager.vue'], resolve);
      }
    }
  ]
};


export default new Router({
  routes: [

    loginRouter,
    indexRouter,
    adminRouter,
    demoRouter,
    {
      path: '/',
      redirect: '/login' // 这样进/ 就会跳转到/login
    },
    page500,
    page403,
    page404

  ]
});
